package cn.stronglink.asset.message.mq.topic;


import java.util.List;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import cn.stronglink.asset.message.mq.topic.entity.CollectBaseReceiverData;
import cn.stronglink.asset.message.mq.topic.entity.CollectDevAddr;
import cn.stronglink.asset.message.mq.topic.entity.CollectR;
import cn.stronglink.asset.module.rfidState.service.RfidStateService;

@Component("readerReceiver")
public class ReaderReceiver implements MessageListener{  

	@Autowired
	private RfidStateService rfidStateService;
	
	public void onMessage(Message message) {
		try {
			if (!(message instanceof ActiveMQTextMessage)) {
				return;
			}
			TextMessage tm = (TextMessage) message;
			String msg = tm.getText();
			CollectBaseReceiverData bm = JSON.parseObject(msg, CollectBaseReceiverData.class);
			String actionCode = bm.getActionCode();
			if("collect002".equals(actionCode)){
				System.out.println("**********接收到2.4G采集到的数据："+bm.getAwsPostData().toString());
				CollectR collectR = JSONObject.parseObject(bm.getAwsPostData().toString(), CollectR.class);
				List<CollectDevAddr> devAddrList =collectR.getDevAddrList();
				 for(CollectDevAddr collectInfo :devAddrList) {
					String lable = collectInfo.getDevAddrCode();// 采集设备号
					List<String> leble24G = collectInfo.getDevInfo();//采集过来的资产标签信息
					rfidStateService.receiver24gLable(lable,leble24G);
				 }
			}
			
		} catch (JMSException e) {
			e.printStackTrace();
		}

	}
}
